<?php

	session_start();
	require("connect.php");
	$link = connect_APO();
	
	if (!session_is_registered('ID')) :
		header('Location: login.php?');
	endif;
	
	require("header+logoutB.php");
	headerL();
	
	include("dateGetter.php");
	
	$sql = sprintf("SELECT * From midweeks ORDER BY StartTime ASC");
	$result = mysql_query($sql);
	$numberMidweeks=0;
	while($row = mysql_fetch_array($result)){
		$numberMidweeks += 1;
		$midweekName[] = $row["Name"];
		$midweekSTime[] = $row["StartTime"];
		$midweekETime[] = $row["EndTime"];
		$midweekDay[] = $row["Day"];
		$midweekSName[] = $row["SName"];
	}

	$numDaysInWeek = 7;
	$daysInWeek = array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");
	
	//build the calendar
	for ($countCal = 0; $countCal<$numberMidweeks; $countCal +=1){
		//go through the week to find which column to place it in
		for($col = 0; $col<$numDaysInWeek; $col += 1){
			if(strcmp(substr($midweekDay[$countCal],0,2),$daysInWeek[$col])==0){
				$colName[$col][]=$midweekName[$countCal];
				$colSTime[$col][]=$midweekSTime[$countCal];
				$colETime[$col][]=$midweekETime[$countCal];
				$colSName[$col][]=$midweekSName[$countCal];
			}
		}
	}
	
	$colIterators= array(0,0,0,0,0,0,0);
	
	
	echo "<html>
<body class='main'>

<FONT class='mainFont'>
  <CENTER>
    <!--<p><img src = 'images/apopic.jpg'></p>-->
    <br>
	<br>
	  <div class='headerTable'>
	  <b class='b1f'></b><b class='b2f'></b><b class='b3f'></b><b class='b4f'></b>
	  <div class='contentf'>
		  <div class = 'headerText'>
				Midweeks:
		  </div>
		  <TABLE id ='calendarTable' BORDER='0' cellspacing='0'>
			<colgroup>
				<col />
				<col id='Sun' />
				<col id='Mon' />
				<col id='Tue' />
				<col id='Wed' />
				<col id='Thu' />
				<col id='Fri' />
				<col id='Sat' />
			</colgroup>
			<thead>
				<tr>
					<th>&nbsp;</th>
					<th scope='col'>$week[$c0]</th>
					<th scope='col'>$week[$c1]</th>
					<th scope='col'>$week[$c2]</th>
					<th scope='col'>$week[$c3]</th>
					<th scope='col'>$week[$c4]</th>
					<th scope='col'>$week[$c5]</th>
					<th scope='col'>$week[$c6]</th>
				</tr>
			</thead>
			<tbody>
				  <tr class='odd'>
				    <td class='hour' scope='row'>9:00 AM</td>";
						$time = "09:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>9:30 AM</td>";
						$time = "09:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>10:00 AM</td>";
						$time = "10:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>10:30 AM</td>";
						$time="10:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>11:00 AM</td>";
						$time="11:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>11:30 AM</td>";
						$time="11:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>12:00 PM</td>";
						$time="12:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>12:30 PM</td>";
						$time="12:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>1:00 PM</td>";
						$time="13:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>1:30 PM</td>";
						$time="13:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>2:00 PM</td>";
						$time="14:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>2:30 PM</td>";
						$time="14:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>3:00 PM</td>";
						$time="15:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>3:30 PM</td>";
						$time="15:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>4:00 PM</td>";
						$time="16:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>4:30 PM</td>";
						$time="16:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>5:00 PM</td>";
						$time="17:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>5:30 PM</td>";
						$time="17:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>6:00 PM</td>";
						$time="18:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>6:30 PM</td>";
						$time="18:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>7:00 PM</td>";
						$time="19:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>7:30 PM</td>";
						$time="19:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>8:00 PM</td>";
						$time="20:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>8:30 PM</td>";
						$time="20:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>9:00 PM</td>";
						$time="21:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>9:30 PM</td>";
						$time="21:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>10:00 PM</td>";
						$time="22:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr>
				    <td class='hour' scope='row'>10:30 PM</td>";
						$time="22:30";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>11:00 PM</td>";
						$time="23:00";
						include("calendarHourElement.php");
				  echo "</tr>
				  <tr class='odd'>
				    <td class='hour' scope='row'>11:30 PM</td>";
						$time="23:30";
						include("calendarHourElement.php");
				  echo "</tr>
			</tbody>
		  </TABLE>
	  </div>
	  <b class='b4f'></b><b class='b3f'></b><b class='b2f'></b><b class='b1f'></b></div>
  </CENTER>
</FONT>
</body>
</html>
";

	require("footer.php");
	footer();
	
	mysql_close($link);

	//function populateRows(){
	//	for
	//}
	
?>
